//
//  BYProductDetailsInfoCell.m
//  OCDemo
//
//  Created by zhumuzhi on 2022/1/5.
//

#import "BYProductDetailsInfoCell.h"
#import "BYProductDetailsModel.h"

@interface BYProductDetailsInfoCell ()

// 售价
@property (nonatomic, strong) UILabel               *price;
// 商品名称
@property (nonatomic, strong) UILabel               *name;

@end

@implementation BYProductDetailsInfoCell

#pragma mark - CellHeight
+ (CGFloat)cellHeightWithModel:(BYProductDetailsModel *)model {
    return 100;
}

#pragma mark - SetData
- (void)setModel:(BYProductDetailsModel *)model {
    _model = model;
 
    self.name.text = model.title;
    self.price.attributedText = [NSMutableAttributedString productPriceText:model.price marketPrice:model.marketprice];
}

#pragma mark - CellHeight
+ (CGFloat)cellHeight {
    return 100.0f;
}

#pragma mark - Init
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self.contentView addSubview:self.price];
        [self.contentView addSubview:self.name];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    [self.price mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(kAutoWithSize(20));
        make.left.equalTo(self.contentView).offset(kAutoWithSize(10));
    }];
    
    [self.name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.price.mas_bottom).offset(kAutoWithSize(5));
        make.left.equalTo(self.contentView).offset(kAutoWithSize(10));
        make.right.equalTo(self.contentView).offset(-kAutoWithSize(10));
    }];
}

#pragma mark - LazyGet

- (UILabel *)price {
    if (!_price) {
        _price = [[UILabel alloc] init];
        _price.font = MZFont(14);
        _price.textColor = UIColorFromRGB(0x333333);
    }
    return _price;
}

- (UILabel *)name {
    if (!_name) {
        _name = [[UILabel alloc]init];
        _name.font = MZBoldFont(16);
        _name.textColor = UIColorFromRGB(0x333333);
        _name.numberOfLines = 0;
    }
    return _name;
}

@end
